package com.toivan.mt.fragment;

import android.os.Bundle;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import com.hwangjr.rxbus.RxBus;
import com.shizhefei.fragment.LazyFragment;
import com.toivan.mt.R;
import com.toivan.mt.adapter.MtFilterAdapter;
import com.toivan.mt.model.MtFilter;
import com.toivan.mt.model.RxBusAction;
import com.toivan.mt.utils.MtSharedPreferences;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

public class MtFilterFragment extends LazyFragment {

    private final List<MtFilter> filterList = new ArrayList<>();

    @Override
    protected void onCreateViewLazy(Bundle savedInstanceState) {
        setContentView(R.layout.fragment_recyclerview);

        filterList.clear();
        filterList.addAll(Arrays.asList(MtFilter.values()));

        RecyclerView filterRV = (RecyclerView) findViewById(R.id.recyclerView);
        MtFilterAdapter filterAdapter = new MtFilterAdapter(filterList, MtSharedPreferences.getInstance().getFilterSelectedPosition());
        filterRV.setLayoutManager(new LinearLayoutManager(getContext(), LinearLayoutManager.HORIZONTAL, false));
        filterRV.setAdapter(filterAdapter);
        filterRV.smoothScrollToPosition(MtSharedPreferences.getInstance().getFilterSelectedPosition());
        RxBus.get().post(RxBusAction.ACTION_FILTER_SELECTION,
            filterList.get(MtSharedPreferences.getInstance().getFilterSelectedPosition()).getFilterName(getContext()));
    }
}
